﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IdentityModel.Tokens;
using System.Collections.ObjectModel;

namespace Sinacor.Infra.Common.Security.Authentication.Credentials
{
    public class SinacorToken : SecurityToken
    {
        SinacorUserInfo _userInfo;
        DateTime effectiveTime = DateTime.UtcNow;
        string _id;
        ReadOnlyCollection<SecurityKey> _securityKeys;
        

        public SinacorUserInfo UserInfo
        {
            get { return _userInfo; }
        }

        public SinacorToken(SinacorUserInfo userInfo): this(userInfo,Guid.NewGuid().ToString()){}

        public SinacorToken(SinacorUserInfo userInfo, string id)
        {
            if (userInfo == null)
            {
                throw new ArgumentNullException("userInfo");
            }
            if (id == null)
            {
                throw new ArgumentNullException("id");
            }

            this._userInfo = userInfo;
            this._id = id;
            
            this._securityKeys = new ReadOnlyCollection<SecurityKey>(new List<SecurityKey>());
        }

        public override string Id
        {
            get { return _id; }
        }

        public override System.Collections.ObjectModel.ReadOnlyCollection<SecurityKey> SecurityKeys
        {
            get { return _securityKeys; }
        }

        public override DateTime ValidFrom
        {
            get { return this.effectiveTime; }
        }

        public override DateTime ValidTo
        {
            get { return this._userInfo.ExpirationDate; }
        }
    }

}
